package admin

import (
	"github.com/gin-gonic/gin"
	"ylm.sl/global"
	"ylm.sl/internal/api/controller"
	"ylm.sl/internal/repository/dao"
	"ylm.sl/internal/service"
	"ylm.sl/middle"
)

type GroupRouter struct {
	service service.IGroupService
}

func (gr *GroupRouter) InitApiRouter(router *gin.RouterGroup) {
	gr.service = service.NewGroupService(dao.NewGroupDao(global.DB),
		(*global.Bloom)["gidRegisterCachePenetrationBloomFilter"])
	groupController := controller.NewGroupController(gr.service)

	privateRouter := router.Group("group")
	privateRouter.Use(middle.VerifyToken())
	privateRouter.Use(middle.UserTransmitFilter())
	{
		// 新增短链接分组
		privateRouter.POST("", groupController.Save)

		// 查询短链接分组集合
		privateRouter.GET("", groupController.ListGroup)

		// 修改短链接分组名称
		privateRouter.PUT("", groupController.UpdateGroup)

		// 删除短链接分组
		privateRouter.DELETE("", groupController.DeleteGroup)

		// 排序短链接分组
		privateRouter.POST("/sort", groupController.SortGroup)
	}
}
